<?php

if (!defined('TOBBIVM'))
	header('location:/template/notrepassing.php');
/**
 * This file is part of TobbiVMShop.
 *
 * TobbiVMShop is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * TobbiVMShop is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with TobbiVMShop.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * create Registerpage
 * get: register.tpl.php
 * used from core.php
 *
 * @version    $Id$
 * @package    TobbiVM-Shop
 * @copyright  Copyright (C) 2012
 * @author     Norbert Gebert
 * @license    GPL3
 */
function contentPage($refPage, $page, $title, $name, $refValidate, $refCart)
{
	$filename = 'module/class/captcha/catcha.php';
	if (is_file($filename))
		include $filename;

	$filename = 'module/class/captcha/catcha.php';
	if (is_file($filename))
		require_once $filename;
	$captcha = new Catcha;

	if ($refValidate->cleanslash($_GET['page']) === 'register' and
		$refValidate->cleanslash($_GET['name']) === 'newregister')
	{ // Verify Userdata
		$pagefile = 'module/register/register.verify.php';
		if (is_file($pagefile))
			include_once($pagefile);
	}
	else if ($refValidate->cleanslash($_GET['page']) === 'register' and
		$refValidate->cleanslash($_GET['name']) === 'register')
	{ // Display registerform
		$pagefile = 'module/register/register.new.php';
		if (is_file($pagefile))
			include_once($pagefile);
	}
	else if ($refValidate->cleanslash($_GET['page']) === 'register' and
		$refValidate->cleanslash($_GET['name']) === 'captcha')
	{ // Test captcha from registerform
		$captcha = unserialize($_SESSION['captcha']);

		if (CAPTCHA_ON)
		{
			if ($captcha->isCorrectResult(intval($_POST['captcha'])) == FALSE)
			{
				// Error in captcha
				message::setErrorRow(_('An incorrect captcha code was entered.'), FALSE);
			}
		}
		$pagefile = 'module/register/register.verify.php';
		if (is_file($pagefile))
			include_once($pagefile);
	}
}

/**
 * produces a random string.
 * @param integer $lengthOfReturnedString
 * @param boolean $noCAPITAL_LETTERS
 * @param boolean $includeNumbersAlso
 * @return string
 */
function random_string($length, $noCaps = false, $addNumbers = false)
{

	// bugfix. to avoid human reading errors, the chars o,O,i,I,l,L,1,0 do not appear any more in the result string.
	$w_s = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'j', 'k', 'm', 'n', 'p', 'q', 'r', 's',
	 't', 'u', 'v', 'w', 'x', 'y', 'z',);
	if ($noCaps === false)
	{
		$w_s = array_merge($w_s, array_map('strtoupper', $w_s));
	}
	if ($addNumbers === true)
	{
		$w_s = array_merge($w_s, array(2, 3, 4, 5, 6, 7, 8, 9,));
	}
	$max = count($w_s) - 1;
	$pw = "";
	for ($i = 0; $i < $length; $i++)
	{
		srand((double) microtime() * 1000000);
		$wg = rand(0, $max);
		$pw.=$w_s[$wg];
	}
	return $pw;
}

?>
